package ModelLayer;
import java.util.HashMap;
import java.util.Iterator;

public class ProductList
{
    private HashMap<Integer,Product> products;
    private static ProductList instance=null;
    
    private ProductList()
    {
        products = new HashMap<>();
    }
    
    public static ProductList getInstance()
    {
        if(instance==null)
        {
            instance = new ProductList();
        }
        
        return instance;
    }
    
    public void addProduct(Product product)
    {
        products.put((Integer)product.getId(),product);
    }
    
    public Product getProduct(int id)
    {
        if(products.containsKey((Integer)id))   return products.get(id);
        
        return null;
    }
    
    public boolean removeProduct(int id)
    {
        return (products.remove(id)!=null);
    }
    
    public Iterator getProductsIterator() { return products.values().iterator(); }
}